--__________         __    __  .__           ___________
--\______   \_____ _/  |__/  |_|  |   ____   \_   _____/__________
-- |    |  _/\__  \\   __\   __\  | _/ __ \   |    __)/  _ \_  __ \
-- |    |   \ / __ \|  |  |  | |  |_\  ___/   |     \(  <_> )  | \/
-- |______  /(____  /__|  |__| |____/\___  >  \___  / \____/|__|
--        \/      \/                     \/       \/
--   _____                     .___.__
--  /     \ _____    ____    __| _/|__| ____  ___________
-- /  \ /  \\__  \  /    \  / __ | |  |/ ___\/  _ \_  __ \
--/    Y    \/ __ \|   |  \/ /_/ | |  \  \__(  <_> )  | \/
--\____|__  (____  /___|  /\____ | |__|\___  >____/|__|
--        \/     \/     \/      \/         \/

--      ui.lua - UI for humans
--
--      (c) Copyright 2005 by Kimmo Merikivi, David Stone
--
--      This program is free software; you can redistribute it and/or modify
--      it under the terms of the GNU General Public License as published by
--      the Free Software Foundation; either version 2 of the License, or
--      (at your option) any later version.
--  
--      This program is distributed in the hope that it will be useful,
--      but WITHOUT ANY WARRANTY; without even the implied warranty of
--      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--      GNU General Public License for more details.
--  
--      You should have received a copy of the GNU General Public License
--      along with this program; if not, write to the Free Software
--      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------




DefineSprites({Name = "sprite-mana", File = "graphics/ui/game/complete_bar.png", Offset = {0, -1}, Size = {31, 4}})
DefineSprites({Name = "sprite-health", File = "graphics/ui/game/health.png", Offset = {0, -4}, Size = {31, 4}})

ShowNoFull()

DefineDecorations({Index = "HitPoints", HideNeutral = false, ShowOpponent = true, CenterX = true,OffsetPercent = {50, 100}, Method = {"sprite", {"sprite-health"}}})
DefineDecorations({Index = "Mana", HideNeutral = true, CenterX = true,OffsetPercent = {50, 100},Method = {"sprite", 	{"sprite-mana"}}})
DefineDecorations({Index = "Transport", HideNeutral = true, CenterX = true,OffsetPercent = {50, 100},Method = 		{"sprite", {"sprite-mana"}}})
DefineDecorations({Index = "Research", HideNeutral = true, CenterX = true,OffsetPercent = {50, 100},Method = 		{"sprite", {"sprite-mana"}}})
DefineDecorations({Index = "Training", HideNeutral = true, CenterX = true,OffsetPercent = {50, 100},Method = 		{"sprite", {"sprite-mana"}}})
DefineDecorations({Index = "UpgradeTo", HideNeutral = true, CenterX = true,OffsetPercent = {50, 100},Method = 		{"sprite", {"sprite-mana"}}})
DefineDecorations({Index = "GiveResource", HideNeutral = false, CenterX = true,OffsetPercent = {50, 100},Method = 	{"sprite", {"sprite-mana"}}})
DefineDecorations({Index = "CarryResource", HideNeutral = false, CenterX = true,OffsetPercent = {50, 100},Method = 	{"sprite", {"sprite-mana"}}})

function DefinePanels(info_panel_x, info_panel_y)

DefinePanelContents(
	{
		Ident = "panel-general-contents"..info_panel_x,
		Pos = {info_panel_x, info_panel_y}, DefaultFont = "game",
		Contents = {
			{ Pos = {88, 52}, Condition = {ShowOpponent = true, HideNeutral = false},
			More = {"LifeBar", {Variable = "HitPoints", Height = 7, Width = 45}}
			},
		{ Pos = {112, 53}, Condition = {ShowOpponent = false, HideNeutral = true},
			More = {"FormattedText2", {
				Font = "small", Variable = "HitPoints", Format = "%d/%d",
				Component1 = "Value", Component2 = "Max", Centered = true}}
		},
		{ Pos = {114, 60}, More = {"Text", {ShowName = true}} },
		--[[
		{ Pos = {12, 153}, Condition = {ShowOpponent = false, HideNeutral = true, Build = "only"},
			More = {"CompleteBar", {Variable = "Build", Width = 152, Height = 12}}
		},
		{ Pos = {50, 154}, Condition = {ShowOpponent = false, HideNeutral = true, Build = "only"},
			More = {"Text", "% Complete"}},
		{ Pos = {107, 78}, Condition = {ShowOpponent = false, HideNeutral = true, Build = "only"},
			More = {"Icon", {Unit = "Worker"}}}
		]]--

	} },
	{
		Ident = "panel-building-contents"..info_panel_x,
		Pos = {info_panel_x, info_panel_y}, DefaultFont = "game",
		Condition = {ShowOpponent = false, HideNeutral = true, Build = "false", Supply = "only", 
		Training = "false",
		UpgradeTo = "false"},
		Contents = {
			{ Pos = {45, 76}, More = {"Text", {Text = "IPC's per turn: ", Variable = "Supply",
			Component = "Max"}} },
	} },

	-- THESE ARE SHOWN TO ONLY PLAYER HIMSELF
	{
		Ident = "panel-all-unit-contents"..info_panel_x,
		Pos = {info_panel_x, info_panel_y},
		DefaultFont = "game",
		Condition = {ShowOpponent = false, HideNeutral = true, Build = "false"},
		Contents = {

			{ Pos = {57, 76}, Condition = {PiercingDamage = "only", Building = "false"},
				More = {"Text", {Text = "Attack: ", Variable = "PiercingDamage"}}
			},
			{ Pos = {57, 91}, Condition = {Armor = "only", Building = "false"},
				More = {"Text", {
				Text = "Defense ", Variable = "Invisible", Stat = true}}
			},
			--{ Pos = {12, 153}, Condition = {Research = "only"},
			--	More = {"CompleteBar", {Variable = "Research", Width = 152, Height = 12}}
			--},
			--{ Pos = {16, 86}, Condition = {Research = "only"}, More = {"Text", "Researching:"}},
			--{ Pos = {50, 154}, Condition = {Research = "only"}, More = {"Text", "% Complete"}},
			--{ Pos = {12, 153}, Condition = {Training = "only"},
			--	More = {"CompleteBar", {Variable = "Training", Width = 152, Height = 12}}
			--},
			--{ Pos = {50, 154}, Condition = {Training = "only"}, More = {"Text", "% Complete"}},
			--{ Pos = {12, 153}, Condition = {UpgradeTo = "only"},
			--	More = {"CompleteBar", {Variable = "UpgradeTo", Width = 152, Height = 12}}
			--},
			--{ Pos = {37,  86}, More = {"Text", "Upgrading:"}, Condition = {UpgradeTo = "only"} },
			--{ Pos = {50, 154}, More = {"Text", "% Complete"}, Condition = {UpgradeTo = "only"} },
			--{ Pos = {16, 148}, Condition = {Mana = "only"},
			--	More = {"CompleteBar", {Variable = "Mana", Height = 16, Width = 140, Border = true}}
			--},
			--{ Pos = {86, 150}, More = {"Text", {Variable = "Mana"}}, Condition = {Mana = "only"} },
			{ Pos = {61, 149}, Condition = {CarryResource = "only"},
				More = {"FormattedText2", {Format = "Carry: %d %s", Variable = "CarryResource",
					Component1 = "Value", Component2 = "Name"}}
			},
	} },

	-- OTHER PLAYERS CAN SEE THESE

	{
	Ident = "panel-attack-unit-contents"..info_panel_x,
	Pos = {info_panel_x, info_panel_y},
	DefaultFont = "game",
	Condition = {ShowOpponent = true, HideNeutral = false, Building = "false", Build = "false"},
	Contents = {
--		{ Pos = {114, 41},
--			 More = {"Text", {Text = Concat("Level ",
--			 InverseVideo(String(ActiveUnitVar("Level", "Value",
--			"Type"))))}}
		}
 }
)

end

function humansScreen(screen_width, screen_height)

local info_panel_x = screen_width - 176 - 4
local info_panel_y = 156
local button_panel_x = 2
local button_panel_y = 18
local button_offset_x = 48
local button_offset_y = 1

DefinePanels(info_panel_x, info_panel_y)

	DefineUI("humans", screen_width, screen_height,
		"normal-font-color", "white",
		"reverse-font-color", "yellow",

--		"filler", {
--			File = "ui/panels/" .. screen_width .. "x" .. screen_height .. "/filler-right.png",
--			Pos = { screen_width - 16, 0}},
--		"filler", {
--			File = "ui/panels/" .. screen_width .. "x" .. screen_height .. "/resource.png",
--			Pos = {176, 0}},
--		"filler", {
--			File = "ui/panels/" .. screen_width .. "x" .. screen_height .. "/statusline.png",
--			Pos = {176, screen_height - 16}},
--		"filler", {
--			File = "ui/panels/menubutton.png",
--			Pos = {0, 0}},
		"filler", {
			File = "ui/panels/minimap.png",
			Pos = {screen_width - 128 - 4, 24}},


		"resources", {
			"ipc", { File = "graphics/ui/game/resources.png", Frame = 0,
			Pos = { 130, 2}, Size = {42, 14}, TextPos = { 130 + 48, 1}},
			"food", { File = "graphics/ui/game/resources.png", Frame = 1,
			Pos = { 230, 2}, Size = {42, 14}, 
			TextPos = { 230 + 48, 1}}},


		"info-panel", {
			"panel", {
--				"file", "ui/panels/infopanel.png",
				"pos", { info_panel_x, info_panel_y},
				"size", {176, 230}
			},
			"panels", {"panel-general-contents"..info_panel_x,
						"panel-attack-unit-contents"..info_panel_x,
						"panel-all-unit-contents"..info_panel_x,
						"panel-building-contents"..info_panel_x},
			"selected", {
				"single", {
					"icon", {
						"pos", {info_panel_x + 88, info_panel_y + 4 }, "style", "icon"}},
				"multiple", {
					"icons", {
						{ "pos", {  55 + info_panel_x, 169}, "style", "icon"},
						{ "pos", {  78 + info_panel_x, 169}, "style", "icon"},
						{ "pos", {  101 + info_panel_x, 169}, "style", "icon"},
						{ "pos", {  124 + info_panel_x, 169}, "style", "icon"},
						{ "pos", {  55 + info_panel_x, 223}, "style", "icon"},
						{ "pos", {  78 + info_panel_x, 223}, "style", "icon"},
						{ "pos", {  101 + info_panel_x, 223}, "style", "icon"},
						{ "pos", {  124 + info_panel_x, 223}, "style", "icon"},
						{ "pos", {  55 + info_panel_x, 277}, "style", "icon"},
						{ "pos", {  78 + info_panel_x, 277}, "style", "icon"},
						{ "pos", {  101 + info_panel_x, 277}, "style", "icon"},
						{ "pos", {  124 + info_panel_x, 277}, "style", "icon"},
						{ "pos", {  55 + info_panel_x, 331}, "style", "icon"},
						{ "pos", {  78 + info_panel_x, 331}, "style", "icon"},
						{ "pos", {  101 + info_panel_x, 331}, "style", "icon"},
						{ "pos", {  124 + info_panel_x, 331}, "style", "icon"},
						{ "pos", {  55 + info_panel_x, 385}, "style", "icon"},
						{ "pos", {  78 + info_panel_x, 385}, "style", "icon"},
						{ "pos", {  101 + info_panel_x, 385}, "style", "icon"},
						{ "pos", {  124 + info_panel_x, 385}, "style", "icon"},
						{ "pos", {  55 + info_panel_x, 439}, "style", "icon"},
						{ "pos", {  78 + info_panel_x, 439}, "style", "icon"},
						{ "pos", {  101 + info_panel_x, 439}, "style", "icon"},
						{ "pos", {  124 + info_panel_x, 439}, "style", "icon"}}, 
					"max-text", {
						"font", "game",
						"pos", { 10, 170}}}
				},

			"training", {
				"single", {
					"text", {
						"text", "Training:",
						"font", "game",
						"pos", { info_panel_x + 37, info_panel_y + 8 + 78}},
					"icon", {
						"pos", { info_panel_x + 110, info_panel_y + 11 + 70},
						"style", "icon"}},
				"multiple", {
					"icons", {
						{ "pos", {  55 + info_panel_x, 169}, "style", "icon"},
						{ "pos", {  78 + info_panel_x, 169}, "style", "icon"},
						{ "pos", {  101 + info_panel_x, 169}, "style", "icon"},
						{ "pos", {  124 + info_panel_x, 169}, "style", "icon"},
						{ "pos", {  55 + info_panel_x, 223}, "style", "icon"},
						{ "pos", {  78 + info_panel_x, 223}, "style", "icon"},
						{ "pos", {  101 + info_panel_x, 223}, "style", "icon"},
						{ "pos", {  124 + info_panel_x, 223}, "style", "icon"},
						{ "pos", {  55 + info_panel_x, 277}, "style", "icon"},
						{ "pos", {  78 + info_panel_x, 277}, "style", "icon"},
						{ "pos", {  101 + info_panel_x, 277}, "style", "icon"},
						{ "pos", {  124 + info_panel_x, 277}, "style", "icon"},
						{ "pos", {  55 + info_panel_x, 331}, "style", "icon"},
						{ "pos", {  78 + info_panel_x, 331}, "style", "icon"},
						{ "pos", {  101 + info_panel_x, 331}, "style", "icon"},
						{ "pos", {  124 + info_panel_x, 331}, "style", "icon"}}}},

			"upgrading", {
				"icon", {
					"pos", { info_panel_x + 110, info_panel_y + 11 + 70},
					"style", "icon"}},

			"researching", {
				"icon", {
					"pos", { info_panel_x + 110, info_panel_y + 11 + 70},
					"style", "icon"}},

			"transporting", {
				"icons", {
						{ "pos", {  55 + info_panel_x, 169}, "style", "icon"},
						{ "pos", {  78 + info_panel_x, 169}, "style", "icon"},
						{ "pos", {  101 + info_panel_x, 169}, "style", "icon"},
						{ "pos", {  124 + info_panel_x, 169}, "style", "icon"},
						{ "pos", {  55 + info_panel_x, 223}, "style", "icon"},
						{ "pos", {  78 + info_panel_x, 223}, "style", "icon"},
						{ "pos", {  101 + info_panel_x, 223}, "style", "icon"},
						{ "pos", {  124 + info_panel_x, 223}, "style", "icon"},
						{ "pos", {  55 + info_panel_x, 277}, "style", "icon"},
						{ "pos", {  78 + info_panel_x, 277}, "style", "icon"},
						{ "pos", {  101 + info_panel_x, 277}, "style", "icon"},
						{ "pos", {  124 + info_panel_x, 277}, "style", "icon"},
						{ "pos", {  55 + info_panel_x, 331}, "style", "icon"},
						{ "pos", {  78 + info_panel_x, 331}, "style", "icon"},
						{ "pos", {  101 + info_panel_x, 331}, "style", "icon"},
						{ "pos", {  124 + info_panel_x, 331}, "style", "icon"},
						{ "pos", {  55 + info_panel_x, 385}, "style", "icon"},
						{ "pos", {  78 + info_panel_x, 385}, "style", "icon"},
						{ "pos", {  101 + info_panel_x, 385}, "style", "icon"},
						{ "pos", {  124 + info_panel_x, 385}, "style", "icon"},
						{ "pos", {  55 + info_panel_x, 439}, "style", "icon"},
						{ "pos", {  78 + info_panel_x, 439}, "style", "icon"},
						{ "pos", {  101 + info_panel_x, 439}, "style", "icon"},
						{ "pos", {  124 + info_panel_x, 439}, "style", "icon"}}},

			"completed-bar", {
				"color", {48, 100, 4}
			}
		},

		"button-panel", {
			"panel", {
				"file", "ui/panels/" ..
				screen_width .. "x" .. screen_height ..
				"/buttonpanel.png",
				"pos", {button_panel_x, button_panel_y}},
			"icons", {
				{"pos", {button_panel_x + button_offset_x * 0, button_panel_y + button_offset_y }, "style", "icon"},
				{"pos", {button_panel_x + button_offset_x * 1, button_panel_y + button_offset_y }, "style", "icon"},
				{"pos", {button_panel_x + button_offset_x * 2, button_panel_y + button_offset_y }, "style", "icon"},
				{"pos", {button_panel_x + button_offset_x * 3, button_panel_y + button_offset_y }, "style", "icon"},
				{"pos", {button_panel_x + button_offset_x * 4, button_panel_y + button_offset_y }, "style", "icon"},
				{"pos", {button_panel_x + button_offset_x * 5, button_panel_y + button_offset_y }, "style", "icon"},
				{"pos", {button_panel_x + button_offset_x * 6, button_panel_y + button_offset_y }, "style", "icon"},
				{"pos", {button_panel_x + button_offset_x * 7, button_panel_y + button_offset_y }, "style", "icon"},
				{"pos", {button_panel_x + button_offset_x * 8, button_panel_y + button_offset_y }, "style", "icon"},
				{"pos", {button_panel_x + button_offset_x * 9, button_panel_y + button_offset_y }, "style", "icon"},
				{"pos", {button_panel_x + button_offset_x * 0, button_panel_y + button_offset_x }, "style", "icon"}},
			"auto-cast-border-color", {0, 0, 252},
		},
		"map-area", {
			Pos = {0,0},--{176, 16},
			Size = {
				screen_width ,--- 176 - 0,
				screen_height }},--- 16 - 16}},

		"menu-panel", {
			"menu-button", {
				Pos = {screen_width - 132, 2},
				Caption = "Menu (~<F10~>)",
				Style = "main"},
			"network-menu-button", {
				Pos = {screen_width - 132 + 6, 2},
				Caption = "Menu",
				Style = "network"},
			"network-diplomacy-button", {
				Pos = {screen_width - 132 + 90, 2},
				Caption = "Diplomacy",
				Style = "network"},
		},

		"minimap", {
			Pos = {screen_width - 128 - 2 , 24 + 2},
			Size = {128, 128}},

		"status-line", {
			TextPos = {2 + 176, 2 + screen_height - 16},
			Font = "game",
			Width = screen_width - 16 - 2 - 176},

		"cursors", {
			Point = "cursor-point",
			Glass = "cursor-glass",
			Cross = "cursor-cross",
			Yellow = "cursor-yellow-hair",
			Green = "cursor-green-hair",
			Red = "cursor-red-hair",
			Scroll = "cursor-scroll",
			ArrowE = "cursor-arrow-e",
			ArrowNE = "cursor-arrow-ne",
			ArrowN = "cursor-arrow-n",
			ArrowNW = "cursor-arrow-nw",
			ArrowW = "cursor-arrow-w",
			ArrowSW = "cursor-arrow-sw",
			ArrowS = "cursor-arrow-s",
			ArrowSE = "cursor-arrow-se"},

--		"menu-panels", {
--			"panel1", "ui/panels/panel_1.png",
--			"panel2", "ui/panels/panel_2.png",
--			"panel3", "ui/panels/panel_3.png",
--			"panel4", "ui/panels/panel_4.png",
--			"panel5", "ui/panels/panel_5.png"},

		"victory-background", "ui/screens/victory.png",
		"defeat-background", "ui/screens/defeat.png")
end

humansScreen(640, 480)
humansScreen(800, 600)
humansScreen(1024, 768)
humansScreen(1280, 960)
humansScreen(1600, 1200)
